package presentacion;

import accesoDatos.GestorAsignacion;
import accesoDatos.GestorEstudiante;
import accesoDatos.GestorMaquina;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import logicaNegocio.ClaseAsignacion;
import logicaNegocio.Estudiante;
import logicaNegocio.Maquina;
import presentacion.recursos.Contador;

/**
 *
 *
 */
public class Asignacion extends javax.swing.JFrame {

    private ArrayList<Contador> listaHilos;
    private Control c;
    private int fila;
    private GestorEstudiante gestorEstudiante;
    private GestorMaquina gestorMaquina;
    private GestorAsignacion gestorAsignacion;
    private boolean existesE;
    private Estudiante est;
    private Maquina maq;
    private String id;
    private String carnet;
    /** Creates new form Asignacion */
    
    Date fechaActual = new Date();//esta clase es para manejar la fecha del sistema
    SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy"); //esta nos permite definir el formato de la fecha
    String cadenaFecha = formato.format(fechaActual);//Aqui asignamos la fecha del sistema en el String cadenaFecha
    Calendar calendario = Calendar.getInstance();//Ya esta clase sirve para obtener la hora
    
   
    
    /**
     * 
     */
    public Asignacion() {
        initComponents();
        setLocationRelativeTo(null);
        this.mensajesAyuda();
        this.gestorEstudiante = null;
        this.gestorMaquina = null;
        this.gestorAsignacion = null;
        this.est = null;
        this.maq = null;
        this.txt_Cedula.setEditable(false);
        this.txt_Carné.setEditable(false);
    }
    
    private void mensajesAyuda(){
        this.txt_Cedula.setToolTipText("Escriba el numero de cedula con el formato: \"X-XXXX-XXXX\", incluyendo los ceros \"0\"");
        this.txt_Carné.setToolTipText("Escriba el numero de carnet Universitario, debe ser de 6 dígitos solamente");
        this.txt_Fecha.setToolTipText("Escriba la fecha del día de hoy bajo el formato: \"XX/XX/XX\"");
        this.txt_Hora.setToolTipText("Escriba la hora de asignacion, con el formato de 24 horas de la siguiente forma: \"XX:XX\"");
    }
    
    /**
     * 
     * @param Cedula
     */
    public void RecibeCedula(String Cedula){
        this.txt_Cedula.setText(Cedula);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        rb_Grupo = new javax.swing.ButtonGroup();
        txt_Carné = new javax.swing.JTextField();
        btn_Buscar = new javax.swing.JButton();
        rb_Carne = new javax.swing.JRadioButton();
        rb_Cedula = new javax.swing.JRadioButton();
        txt_Cedula = new javax.swing.JTextField();
        txt_NombreCompleto = new javax.swing.JTextField();
        lb_Carrera = new javax.swing.JLabel();
        lb_EstadoEstudiante = new javax.swing.JLabel();
        lb_NumeroMaquina = new javax.swing.JLabel();
        txt_Carrera = new javax.swing.JTextField();
        lb_InformacionEstudiante = new javax.swing.JLabel();
        lb_NombreCompleto = new javax.swing.JLabel();
        lb_Sede = new javax.swing.JLabel();
        txt_Sede = new javax.swing.JTextField();
        btn_Asignar = new javax.swing.JButton();
        lb_Fecha = new javax.swing.JLabel();
        lb_HoraInicio = new javax.swing.JLabel();
        txt_Hora = new javax.swing.JTextField();
        txt_Fecha = new javax.swing.JTextField();
        txt_NumeroMaquina = new javax.swing.JTextField();
        lb_ImagenEstado = new javax.swing.JLabel();
        lb_Estado = new javax.swing.JLabel();
        lb_Funcionario = new javax.swing.JLabel();
        btn_Cancelar = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        txt_Facultad = new javax.swing.JTextField();
        lb_Facultad = new javax.swing.JLabel();
        txt_Escuela = new javax.swing.JTextField();
        lb_Escuela = new javax.swing.JLabel();

        setTitle("Asignacion de Equipo");

        txt_Carné.setFont(new java.awt.Font("Tahoma", 1, 11));

        btn_Buscar.setFont(new java.awt.Font("Tahoma", 1, 11));
        btn_Buscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentacion/imagenes/Buscar.png"))); // NOI18N
        btn_Buscar.setText("Buscar");
        btn_Buscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_BuscarActionPerformed(evt);
            }
        });
        btn_Buscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                none(evt);
            }
        });

        rb_Grupo.add(rb_Carne);
        rb_Carne.setFont(new java.awt.Font("Tahoma", 1, 11));
        rb_Carne.setText("Carné:");
        rb_Carne.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                rb_CarneMouseClicked(evt);
            }
        });
        rb_Carne.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rb_CarneActionPerformed(evt);
            }
        });

        rb_Grupo.add(rb_Cedula);
        rb_Cedula.setFont(new java.awt.Font("Tahoma", 1, 11));
        rb_Cedula.setText("Cédula:");
        rb_Cedula.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        rb_Cedula.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                rb_CedulaMouseClicked(evt);
            }
        });
        rb_Cedula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rb_CedulaActionPerformed(evt);
            }
        });

        txt_Cedula.setFont(new java.awt.Font("Tahoma", 1, 11));
        txt_Cedula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_CedulaActionPerformed(evt);
            }
        });

        txt_NombreCompleto.setEditable(false);
        txt_NombreCompleto.setFont(new java.awt.Font("Tahoma", 1, 11));

        lb_Carrera.setFont(new java.awt.Font("Tahoma", 1, 11));
        lb_Carrera.setText("Carrera:");

        lb_EstadoEstudiante.setFont(new java.awt.Font("Tahoma", 1, 11));
        lb_EstadoEstudiante.setText("Estado Estudiante:");

        lb_NumeroMaquina.setFont(new java.awt.Font("Tahoma", 1, 11));
        lb_NumeroMaquina.setText("Número de Máquina:");

        txt_Carrera.setEditable(false);
        txt_Carrera.setFont(new java.awt.Font("Tahoma", 1, 11));

        lb_InformacionEstudiante.setFont(new java.awt.Font("Tahoma", 1, 11));
        lb_InformacionEstudiante.setText("Información de Estudiante:");

        lb_NombreCompleto.setFont(new java.awt.Font("Tahoma", 1, 11));
        lb_NombreCompleto.setText("Nombre Completo:");

        lb_Sede.setFont(new java.awt.Font("Tahoma", 1, 11));
        lb_Sede.setText("Sede:");

        txt_Sede.setEditable(false);
        txt_Sede.setFont(new java.awt.Font("Tahoma", 1, 11));

        btn_Asignar.setFont(new java.awt.Font("Tahoma", 1, 11));
        btn_Asignar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentacion/imagenes/Aceptar.png"))); // NOI18N
        btn_Asignar.setText("Asignar");
        btn_Asignar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_AsignarActionPerformed(evt);
            }
        });

        lb_Fecha.setFont(new java.awt.Font("Tahoma", 1, 11));
        lb_Fecha.setText("Fecha:");

        lb_HoraInicio.setFont(new java.awt.Font("Tahoma", 1, 11));
        lb_HoraInicio.setText("Hora Inicio:");

        txt_Hora.setEditable(false);
        txt_Hora.setFont(new java.awt.Font("Tahoma", 1, 11));
        txt_Hora.setText("00:00");

        txt_Fecha.setEditable(false);
        txt_Fecha.setFont(new java.awt.Font("Tahoma", 1, 11));
        txt_Fecha.setText("00/00/00");

        txt_NumeroMaquina.setEditable(false);
        txt_NumeroMaquina.setFont(new java.awt.Font("Tahoma", 1, 11));

        lb_Estado.setFont(new java.awt.Font("Tahoma", 1, 11));
        lb_Estado.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentacion/imagenes/EstadoDefault.PNG"))); // NOI18N

        lb_Funcionario.setText("Funcionario");
        lb_Funcionario.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lb_FuncionarioMouseClicked(evt);
            }
        });

        btn_Cancelar.setFont(new java.awt.Font("Tahoma", 1, 11));
        btn_Cancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentacion/imagenes/Cancelar.png"))); // NOI18N
        btn_Cancelar.setText("Cancelar");
        btn_Cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_CancelarActionPerformed(evt);
            }
        });

        txt_Facultad.setEditable(false);
        txt_Facultad.setFont(new java.awt.Font("Tahoma", 1, 11));

        lb_Facultad.setFont(new java.awt.Font("Tahoma", 1, 11));
        lb_Facultad.setText("Facultad:");

        txt_Escuela.setEditable(false);
        txt_Escuela.setFont(new java.awt.Font("Tahoma", 1, 11));

        lb_Escuela.setFont(new java.awt.Font("Tahoma", 1, 11));
        lb_Escuela.setText("Escuela:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txt_Cedula, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(rb_Cedula))
                        .addGap(66, 66, 66))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(245, Short.MAX_VALUE)
                        .addComponent(btn_Buscar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rb_Carne)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lb_Funcionario)
                            .addComponent(txt_Carné, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(91, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lb_InformacionEstudiante)
                .addContainerGap(477, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lb_NombreCompleto)
                .addContainerGap(525, Short.MAX_VALUE))
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 639, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(176, 176, 176)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lb_ImagenEstado)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lb_Fecha)
                                    .addComponent(txt_Fecha, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 111, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addComponent(txt_Hora, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(lb_HoraInicio, javax.swing.GroupLayout.Alignment.LEADING))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txt_NombreCompleto, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 577, Short.MAX_VALUE))
                .addGap(52, 52, 52))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(368, Short.MAX_VALUE)
                .addComponent(btn_Cancelar)
                .addGap(18, 18, 18)
                .addComponent(btn_Asignar)
                .addGap(25, 25, 25))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(txt_Facultad, javax.swing.GroupLayout.DEFAULT_SIZE, 577, Short.MAX_VALUE)
                .addGap(52, 52, 52))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lb_Facultad)
                .addContainerGap(578, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(txt_Sede, javax.swing.GroupLayout.DEFAULT_SIZE, 577, Short.MAX_VALUE)
                .addGap(52, 52, 52))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lb_Sede)
                .addContainerGap(598, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(txt_Carrera, javax.swing.GroupLayout.DEFAULT_SIZE, 577, Short.MAX_VALUE)
                .addGap(52, 52, 52))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lb_Carrera)
                .addContainerGap(583, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txt_Escuela, javax.swing.GroupLayout.DEFAULT_SIZE, 577, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lb_Escuela)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 532, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(52, 52, 52))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lb_NumeroMaquina)
                .addContainerGap(514, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lb_EstadoEstudiante)
                .addGap(18, 18, 18)
                .addComponent(lb_Estado)
                .addContainerGap(478, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(txt_NumeroMaquina, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(533, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rb_Cedula)
                    .addComponent(rb_Carne))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txt_Cedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txt_Carné, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_Buscar)
                    .addComponent(lb_Funcionario, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(13, 13, 13)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(lb_InformacionEstudiante)
                .addGap(18, 18, 18)
                .addComponent(lb_NombreCompleto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txt_NombreCompleto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(lb_Escuela)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txt_Escuela, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lb_Carrera)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txt_Carrera, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lb_Sede, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txt_Sede, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lb_Facultad, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txt_Facultad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lb_ImagenEstado)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lb_NumeroMaquina)
                        .addComponent(lb_Fecha)
                        .addComponent(lb_HoraInicio)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txt_Hora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txt_Fecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txt_NumeroMaquina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lb_EstadoEstudiante)
                    .addComponent(lb_Estado))
                .addGap(15, 15, 15)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(btn_Cancelar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_Asignar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public void obtenerGestores(GestorEstudiante ge, GestorMaquina gm, GestorAsignacion ga){
        this.gestorEstudiante = ge;
        this.gestorMaquina = gm;
        this.gestorAsignacion = ga;
    }
    
    private void txt_CedulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_CedulaActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txt_CedulaActionPerformed

    private boolean validarCedula(){
        String ced = this.txt_Cedula.getText();
        Pattern p = Pattern.compile("^[1-7]\\-\\d{4}\\-\\d{4}");
        Matcher m = p.matcher(ced);
        if(m.find()){
            return true;
        }
        else{
                 return false;
        }
    }
    
    
     private boolean validarCarne(){
         String crn = this.txt_Carné.getText();
         Pattern c = Pattern.compile("\\d{6}");
         Matcher a = c.matcher(crn);
         if(a.find()){
             return true;
         }
         else{
             return false;
         }
     }
    
    private void llenarVariablesIdentificacion() {
        if(this.txt_Carné.isEditable()){
            this.carnet = this.txt_Carné.getText();
            this.id = "";
        }
        else{
            this.carnet = "";
            this.id = this.txt_Cedula.getText();
        }
    }
     
    private void BuscarDatos(){
        //Completar el Metodo Buscar
        if(!this.txt_Carné.isEditable() && !this.txt_Cedula.isEditable()){
            JOptionPane.showInternalMessageDialog(rootPane, "ERROR: Debe de elegir primer el tipo de busqueda (Por cedula o carnet)");
            return;
        }
        this.llenarVariablesIdentificacion();
        if(!this.id.equals(""))
            this.est = this.gestorEstudiante.consultarDato(id);
        else
            this.est = this.gestorEstudiante.consultarDatoPorCarnet(this.carnet);
        if(this.validarEstudiante(est)){
            this.carnet = est.getCarnet();
            this.id = est.getIdentificacion();
            this.existesE = true;
            this.txt_NombreCompleto.setText(est.getNombre());
            this.txt_Escuela.setText(est.getEscuela());
            this.txt_Carrera.setText(est.getCarrera());
            this.txt_Sede.setText(est.getSede());
            this.txt_Facultad.setText(est.getFacultad());
            this.definirEstado(est.getEstado());
        }else{
            this.buscarDatosRegistro();
        }
        this.llenarFecha();
    }
    
    private void btn_BuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_BuscarActionPerformed
        this.BuscarDatos();
}//GEN-LAST:event_btn_BuscarActionPerformed

    private void buscarDatosRegistro(){
        if(!this.id.equals(""))
            this.est = this.gestorEstudiante.consultarIdPorRegistro(id);
        else
            this.est = this.gestorEstudiante.consultarCarnetPorRegistro(this.carnet);
        if(this.validarEstudiante(est)){
            this.id = est.getIdentificacion();
            this.carnet = est.getCarnet();
            this.existesE = false;
            this.txt_NombreCompleto.setText(est.getNombre());
            this.txt_Escuela.setText(est.getEscuela());
            this.txt_Carrera.setText(est.getCarrera());
            this.txt_Sede.setText(est.getSede());
            this.txt_Facultad.setText(est.getFacultad());
            this.definirEstado(1);
        }
        else{
            JOptionPane.showMessageDialog(rootPane, "ERROR: El Estudiante no se encuentra matriculado este semestre");
            this.setVisible(false);
        }
    }
    
    private void definirEstado(int e){
        ImageIcon icono = null;
        if(e == 1)
            icono = new ImageIcon(getClass().getResource("/presentacion/imagenes/Estado2.PNG"));
        else if(e == 2)
            icono = new ImageIcon(getClass().getResource("/presentacion/imagenes/Estado1.PNG"));
        else if(e == 3)
            icono = new ImageIcon(getClass().getResource("/presentacion/imagenes/Estado1.PNG"));
        else
            icono = new ImageIcon(getClass().getResource("/presentacion/imagenes/Estado3.PNG"));
        this.lb_Estado.setIcon(icono);
    }
    
    private boolean validarCampoBuscar(){
        if(this.rb_Cedula.isSelected()){
            if(this.txt_Cedula.getText().equals(""))
                return false;
        }
        else{
            if(this.txt_Carné.getText().equals(""))
                return false;
        }
        return true;
    }
    
    private void llenarFecha(){
        this.txt_Fecha.setText(this.cadenaFecha);
        String hora;
        String minutos;
        hora = calendario.get(Calendar.HOUR_OF_DAY)+"";//Aqui le asignamos al int hora, la hora del sistema(formato de 24 horas)
        minutos = calendario.get(Calendar.MINUTE)+"";//Aqui le asignamos al int minutos, los minutos del sistema
        if(hora.length() == 1)
            hora = "0"+hora;
        if(minutos.length() == 1)
            minutos = "0"+minutos;
        this.txt_Hora.setText(hora+":"+minutos);
    }
    
    private void rb_CedulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rb_CedulaActionPerformed
        if(this.rb_Cedula.isSelected()){
            this.txt_Cedula.setEditable(true);
            if(this.txt_Carné.isEditable())
                this.txt_Carné.setEditable(false);
        }
}//GEN-LAST:event_rb_CedulaActionPerformed

    private void rb_CarneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rb_CarneActionPerformed
    if(this.rb_Carne.isSelected()){
        this.txt_Carné.setEditable(true);
        if(this.txt_Cedula.isEditable())
            this.txt_Cedula.setEditable(false);
    }
}//GEN-LAST:event_rb_CarneActionPerformed

    
    private boolean validarNombre(){
        if(!this.txt_NombreCompleto.getText().equals("")){     
             return true;
        }
        else{
           return false;
        }
    }
    
    private boolean validarCarrera(){
        if(!this.txt_Carrera.getText().equals("")){
                return true;
            }
           else{
                 return false;
        }
    }
    
    private boolean validarFacultad(){
        if(!this.txt_Facultad.getText().equals("")){
                return true;
            }
           else{
                 return false;
        }
    }
    
    private boolean validarFecha(){
        String fecha = this.txt_Fecha.getText();
        if(!this.txt_Fecha.getText().equals("")){
          Pattern f = Pattern.compile("\\d{2}\\/\\d{2}\\/\\d{2}");
          Matcher ch = f.matcher(fecha);
          if(ch.find()){
            return true;
          }
          else{
            return false;
          }
        }
         else{
                 return false;
        }
    }
    
    private boolean validarHora(){
        String hor = this.txt_Hora.getText();
        if(!this.txt_Hora.getText().equals("")){
          Pattern h = Pattern.compile("\\d{2}\\:\\d{2}");
          Matcher r = h.matcher(hor);
          if(r.find()){
            return true;
          }
          else{
            return false;
          }
        }
           else{
                 return false;
        }
    }
    
    private boolean validarEstudiante(Estudiante e){
        if(e == null)
            return false;
        return true;
    }
    
    private boolean validarMaquina(Maquina m){
        if(m == null)
            return false;
        return true;
    }
    
    private void asignarEstudiante(){
        if(validarNombre() == true){
            if(validarCarrera() == true){
                if(validarFacultad() == true){
                        if(validarFecha() == true){
                            if(validarHora() == true){
                                //JOptionPane.showMessageDialog(rootPane, ("Todos los datos se ingresaron correctamente"));
                                String horaFinal = this.calcularHoraFinal(this.txt_Hora.getText());
                                this.c.asignarComputadora(fila, id, this.txt_Hora.getText(), horaFinal);
                                this.maq = this.gestorMaquina.consultarDato(this.txt_NumeroMaquina.getText());
                                if(!this.validarMaquina(maq)){
                                    this.maq = new Maquina(Integer.parseInt(this.txt_NumeroMaquina.getText()),
                                            1);
                                    this.gestorMaquina.ingresarDato(maq);
                                }else{
                                    this.maq.setEstado(1);
                                    this.gestorMaquina.modificarDato(maq);
                                }
                                if(!this.existesE)
                                    this.gestorEstudiante.ingresarDato(est);
                                this.gestorAsignacion.ingresarDato(
                                        new ClaseAsignacion(est.getIdentificacion(), 
                                                maq.getNumeroMaquina(), 
                                                this.txt_Fecha.getText(), 
                                                this.txt_Hora.getText(),horaFinal)
                                        );
                                this.c.cargarTabla();
                                Contador contador = new Contador(fila, c);
                                this.listaHilos.add(contador);
                                contador.getHilo().start();
                                this.c.setListaHilos(this.listaHilos);
                                this.txt_NombreCompleto.setText("");
                                this.txt_Carrera.setText("");
                                this.txt_Facultad.setText("");
                                this.txt_Fecha.setText("");
                                this.txt_Hora.setText("");
                                this.dispose();
                            }
                            else{
                               JOptionPane.showMessageDialog(rootPane, ("Hora Incorrecta")); 
                            }
                        }
                        else { 
                            JOptionPane.showMessageDialog(rootPane, ("Fecha Incorrecta"));
                        }
                    }
                    
                else{
                    JOptionPane.showMessageDialog(rootPane, ("Facultad Incorrecta"));
                }
            }
            else{
                JOptionPane.showMessageDialog(rootPane, ("Carrera Incorrecta"));
            }
        }
        else{
            JOptionPane.showMessageDialog(rootPane, ("Nombre Incorrecto"));
        }
    }
    
    private void btn_AsignarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_AsignarActionPerformed
        this.asignarEstudiante();
    }//GEN-LAST:event_btn_AsignarActionPerformed

    private String calcularHoraFinal(String hora){
        char v1 = hora.charAt(0);
        char v2 = hora.charAt(1);
        char v3 = hora.charAt(3);
        char v4 = hora.charAt(4);
        int v1i = Integer.parseInt(v1+"");
        int val = 0;
        if(v1i == 0)
            val = Integer.parseInt(v2+"");
        else{
            String val2 = ((v1+"")+(v2+""));
            val = Integer.parseInt(val2);
        }
        val = val+3;
        if((val-3) <= 6)
            return v1+""+val+""+":"+v3+""+v4;
        else 
            return val+""+":"+v3+""+v4;
    }
    
    private void none(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_none
        // TODO add your handling code here:
    }//GEN-LAST:event_none

    private void lb_FuncionarioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lb_FuncionarioMouseClicked
        AsignarFuncionario af = new AsignarFuncionario();
        this.setVisible(false);
        af.getControl(this.fila, this.txt_NumeroMaquina.getText(), this.c);
        af.getGestores(gestorAsignacion, gestorMaquina);
        af.setVisible(true);
        
    }//GEN-LAST:event_lb_FuncionarioMouseClicked

private void btn_CancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_CancelarActionPerformed
    setVisible(false);
}//GEN-LAST:event_btn_CancelarActionPerformed

private void rb_CedulaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rb_CedulaMouseClicked
    
}//GEN-LAST:event_rb_CedulaMouseClicked

private void rb_CarneMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rb_CarneMouseClicked

}//GEN-LAST:event_rb_CarneMouseClicked

/**
 * 
 * @param con
 * @param numComp
 * @param fila
 */
public void getControl(Control con, String numComp, int fila){
        this.c = con;
        txt_NumeroMaquina.setText(numComp);
        this.fila = fila;
        this.listaHilos = this.c.getListaHilos();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_Asignar;
    private javax.swing.JButton btn_Buscar;
    private javax.swing.JButton btn_Cancelar;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lb_Carrera;
    private javax.swing.JLabel lb_Escuela;
    private javax.swing.JLabel lb_Estado;
    private javax.swing.JLabel lb_EstadoEstudiante;
    private javax.swing.JLabel lb_Facultad;
    private javax.swing.JLabel lb_Fecha;
    private javax.swing.JLabel lb_Funcionario;
    private javax.swing.JLabel lb_HoraInicio;
    private javax.swing.JLabel lb_ImagenEstado;
    private javax.swing.JLabel lb_InformacionEstudiante;
    private javax.swing.JLabel lb_NombreCompleto;
    private javax.swing.JLabel lb_NumeroMaquina;
    private javax.swing.JLabel lb_Sede;
    private javax.swing.JRadioButton rb_Carne;
    private javax.swing.JRadioButton rb_Cedula;
    private javax.swing.ButtonGroup rb_Grupo;
    private javax.swing.JTextField txt_Carné;
    private javax.swing.JTextField txt_Carrera;
    private javax.swing.JTextField txt_Cedula;
    private javax.swing.JTextField txt_Escuela;
    private javax.swing.JTextField txt_Facultad;
    private javax.swing.JTextField txt_Fecha;
    private javax.swing.JTextField txt_Hora;
    private javax.swing.JTextField txt_NombreCompleto;
    private javax.swing.JTextField txt_NumeroMaquina;
    private javax.swing.JTextField txt_Sede;
    // End of variables declaration//GEN-END:variables

  
}
